package com.example.common.aop;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.example.common.exception.CommonException;
import com.example.system.DO.UserDO;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Slf4j
@Component
public class TestAop {
    @Pointcut("@annotation(com.example.common.aop.TestAll)")
    private void getLogPointCut() {
    }
    @Around("getLogPointCut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        UserDO userDO = (UserDO)StpUtil.getSession().get("loginUser");
        if (ObjectUtil.isNotEmpty(userDO.getAge()) && userDO.getAge().equals(18)){
            return proceedingJoinPoint.proceed();
        }
        throw  new CommonException(402, "无角色权限");
    }
//    @Around("@annotation(testAll)")
//    public Object around(ProceedingJoinPoint proceedingJoinPoint, TestAll testAll){
//        throw  new CommonException("402", "无角色权限");
//    }
}
